import React, { PureComponent } from 'react';
import { connect } from 'dva';

import { Form, Button, InputNumber, Modal, Input, Select, AutoComplete } from 'antd';

const { Item: FormItem } = Form;

const ModelName = 'relationer';
@connect(({ loading }) => ({
  loading: loading.models[ModelName],
}))
@Form.create()
class Comp extends PureComponent {

  constructor(props) {
    super(props);

    const { getInstance } = props;
    if (typeof getInstance === 'function') {
      getInstance(this);
    }
  }

  handleSubmit(e) {
    e.preventDefault();
    const { form } = this.props;

    let vm = {};

    // Header FORM
    form.validateFields((err, values) => {
      if (err) {
        return;
      }

      vm = {
        ...vm,
        ...values,
      };
    });
    this.props.onOk(vm);
  }

  render() {
    const {
      form: { getFieldDecorator },
    } = this.props;
    const { visible, onOk, onCancel } = this.props;

    const formLayout = {
      labelCol: {
        sm: { span: 24 },
        lg: { span: 5 },
      },
      wrapperCol: {
        sm: { span: 24 },
        lg: { span: 15 },
      },
    };

    return (
      <Modal title="添加" destroyOnClose visible={visible} onOk={(e) => this.handleSubmit(e)} onCancel={onCancel}>
        <Form onSubmit={this.handleSubmit}>
          <FormItem label="单位名称" {...formLayout}>
            {getFieldDecorator('objectName', {
              rules: [{ required: true, message: '单位名称不能为空' }],
            })(<Input />)}
          </FormItem>

          <FormItem label="地址" {...formLayout}>
            {getFieldDecorator('address', {
              initialValue: '',
            })(<Input.TextArea rows={5} />)}
          </FormItem>

        </Form>
      </Modal >
    );
  }
}

export default Comp;
